local xushiz = fk.CreateSkill {
  name = "xushiz",
}

local getShade = function (room, n)
  local ids = {}
  for _, id in ipairs(room.void) do
    if n <= 0 then break end
    if Fk:getCardById(id).name == "shade" then
      room:setCardMark(Fk:getCardById(id), MarkEnum.DestructIntoDiscard, 1)
      table.insert(ids, id)
      n = n - 1
    end
  end
  while n > 0 do
    local card = room:printCard("shade", Card.Spade, 1)
    room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
    table.insert(ids, card.id)
    n = n - 1
  end
  return ids
end


xushiz:addEffect("active", {
  anim_type = "offensive",
  prompt = "#xushiz-invoke",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  card_num = 0,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = effect.from
    local list = room:askForYiji(
      player,
      player:getCardIds("he"),
      room:getOtherPlayers(player, false),
      self.name,
      1,
      999,
      "#xushiz-invoke",
      nil,
      false,
      1
    )
    if player.dead then return end
    local x = 0
    for _, value in pairs(list) do
      if #value > 0 then
        x = x + 2
      end
    end
    room:moveCards({
      ids = getShade(room, x),
      to = player,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonPrey,
      proposer = player,
      skillName = self.name,
      moveVisible = true,
    })
  end,
})

return xushiz